package cn.iocoder.yudao.module.english.service.level;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.english.controller.admin.level.vo.LevelManagementPageReqVO;
import cn.iocoder.yudao.module.english.controller.admin.level.vo.LevelManagementSaveReqVO;
import cn.iocoder.yudao.module.english.dal.dataobject.level.LevelManagementDO;
import cn.iocoder.yudao.module.english.dal.mysql.level.LevelManagementMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;

/**
 * 级别管理 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class LevelManagementServiceImpl implements LevelManagementService {

    @Resource
    private LevelManagementMapper levelManagementMapper;

    @Override
    public Long createLevelManagement(LevelManagementSaveReqVO createReqVO) {
        // 插入
        LevelManagementDO levelManagement = BeanUtils.toBean(createReqVO, LevelManagementDO.class);
        levelManagementMapper.insert(levelManagement);
        // 返回
        return levelManagement.getId();
    }

    @Override
    public void updateLevelManagement(LevelManagementSaveReqVO updateReqVO) {
        // 校验存在
        validateLevelManagementExists(updateReqVO.getId());
        // 更新
        LevelManagementDO updateObj = BeanUtils.toBean(updateReqVO, LevelManagementDO.class);
        levelManagementMapper.updateById(updateObj);
    }

    @Override
    public void deleteLevelManagement(Long id) {
        // 校验存在
        validateLevelManagementExists(id);
        // 删除
        levelManagementMapper.deleteById(id);
    }

    private void validateLevelManagementExists(Long id) {
        if (levelManagementMapper.selectById(id) == null) {
//            throw exception(LEVEL_MANAGEMENT_NOT_EXISTS);
        }
    }

    @Override
    public LevelManagementDO getLevelManagement(Long id) {
        return levelManagementMapper.selectById(id);
    }

    @Override
    public PageResult<LevelManagementDO> getLevelManagementPage(LevelManagementPageReqVO pageReqVO) {
        return levelManagementMapper.selectPage(pageReqVO);
    }

}